package com.alpha.feign.common.entity;

import com.alpha.core.entity.AlphaEntity;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.experimental.Accessors;

import javax.validation.constraints.NotNull;

/**
 * 字段属性
 *
 * @author alpha-build
 * @since 2022-01-01
 */
@Data
@Schema(name = "字段属性")
@Accessors(chain = true)
@NoArgsConstructor
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true)
public class Attribute extends AlphaEntity {
    @NotNull(message = "服务名不能为空")
    @Schema(description = "服务名")
    private String serviceName;

    @NotNull(message = "表名不能为空")
    @Schema(description = "表名")
    private String tableName;

    @NotNull(message = "列名不能为空")
    @Schema(description = "列名")
    private String columnName;

    @NotNull(message = "类型不能为空")
    @Schema(description = "类型")
    private String columnType;

    @NotNull(message = "展示名不能为空")
    @Schema(description = "展示名")
    private String visualName;

    @NotNull(message = "是否必填不能为空")
    @JsonFormat(shape = JsonFormat.Shape.NUMBER)
    @Schema(description = "是否必填")
    private Boolean required;

    @NotNull(message = "是否扩展不能为空")
    @JsonFormat(shape = JsonFormat.Shape.NUMBER)
    @Schema(description = "是否扩展")
    private Boolean extended;

    @Schema(description = "格式")
    private String format;

    @Schema(description = "前端属性")
    @TableField(typeHandler = JacksonTypeHandler.class)
    private Object properties;

    @SuppressWarnings("unused")
    public Attribute(String serviceName, String tableName, String columnName, String columnType, String visualName, Boolean required, Boolean extended) {
        // NotNull fields
        this.serviceName = serviceName;
        this.tableName = tableName;
        this.columnName = columnName;
        this.columnType = columnType;
        this.visualName = visualName;
        this.required = required;
        this.extended = extended;
    }
}
